package com.mao.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mao.common.BaseContext;
import com.mao.entity.User;
import com.mao.mapper.UserMapper;
import com.mao.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;

@Service
@Slf4j
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    //把yml配置的邮箱号赋值到from
    @Value("${spring.mail.username}")
    //邮件发送人
    private String from;
    //发送邮件需要的对象
    @Autowired
    private JavaMailSender javaMailSender;
    @Override
    public void sendMsg(String to, String subject, String text) {
        //发送简单邮件，简单邮件不包括附件等别的
            SimpleMailMessage message = new SimpleMailMessage();
            message.setFrom(from);
            message.setTo(to);
            message.setSubject(subject);
            message.setText(text);
            //发送邮件
            javaMailSender.send(message);

    }

    @Override
    public void logout(HttpSession session) {
        session.removeAttribute("user");
    }
}
